
> ###############################################
> #Figure 1: Ranked Occupational Risk By Source 
> #Author: Raluca L. Pahontu
> ###############################################
> 
> data<- read.csv("ranks.csv") 

> data$isco2 <- data$SkillSpec.Rank

> data2 <- melt(data, id="isco2")

> data2 <- data2[22:105,]

> data2$isco2 <- as.factor(data2$isco2)

> data2$isco2 <- as.factor(data2$isco2)

> fig1 <- ggplot(data2, aes(x=isco2, y=value, group=variable)) 

> fig1 + geom_point(aes(shape=variable, colour=isco2), size=2, stroke=1.5) +
+   xlab("ISCO-2 Classification") + 
+   ylab("Ranked Risk") + theme_bw() +
+   geom_segment(x=1, xend=21, y=1, yend=21, col="grey90", linetype="dotted", lwd=.4) +
+   theme(panel.grid.minor=element_blank(),
+         panel.grid.major = element_blank(),
+         panel.border = element_blank(),
+         axis.title.y = element_text(margin = margin(t = 0, r = 15, b = 0, l = 0), size=15),
+         axis.title.x = element_text(margin = margin(t = 10, r = 20, b = 0, l = 0), size=15),
+         axis.ticks.length=unit(0.3,"cm"),
+         axis.text = element_text(colour ="black", size=12)) +
+   geom_vline(xintercept=seq(1.5,20.5, by=1), linetype="dotted", color="grey60", lwd=.2) +
+   geom_hline(yintercept = 0, linetype="dotted", color="grey70", lwd=.2) +
+   scale_shape_discrete(solid=FALSE, labels=c("RTI", "Skill Specific", "OUR", "Offshore"), name="Type") + 
+   scale_colour_manual(values=c("black", "grey30", "grey40", "grey60", "grey70", "grey60", "grey40", "grey30",
+                                "grey40", "grey60", "grey70", "grey60", "grey60", "grey70", "grey80", "grey90",
+                                "grey80", "grey70", "grey60", "grey50", "grey40"), guide=FALSE) +
+   scale_x_discrete(breaks = c(4,  2, 13,  5,  7, 15, 14,  8,  3, 11,  6,  1, 12, 10, 20, 18,21, 19,  9, 17, 16), 
+                    labels = c("12","13","21","22","24","31","32","33","41","42","51","52","71","72","73","74","81","82","83","91","93"))+
+   
+   scale_y_continuous(breaks=c(0, 21), labels=c("Min", "Max")) +
+   coord_cartesian(xlim = c(1, 21), ylim=c(1, 21)) + 
+   geom_segment(x=0.4, xend=0.4, y=0, yend=21, col="black") +
+   geom_segment(y=0, yend=0, x=0.99, xend=21.01, col="black") 

> ggsave("fig1_ranked.pdf")

> ###############################################
> #Figure 2: Defining Risk Type
> #Author: Raluca L. Pahontu
> ###############################################
> 
> require(plotrix)

> #Venn Diagram 
> pdf("venn.pdf", width = 9.44, height = 7.08)

> par(mar = c(0,0.7,0,.5)) 

> plot(1:5,seq(1,10,length=5),type="n",xlab="",ylab="", labels=FALSE, frame.plot = FALSE, axes=F)

> draw.circle(2.2,7,0.6,border="black",lty=1,lwd=1.2)

> draw.circle(3,7,0.6,border="black",lty=1,lwd=1.2)

> draw.circle(2.6,5,0.6,border="black",lty=1,lwd=1.2)

> text(2.1,7, bquote(rho[2]), size=1.2)

> text(3.1,7, bquote(rho[2]), size=1.2)

> text(2.6,4.5, bquote(rho[2]), size=1.2)

> text(3.3,4.7, bquote(rho[2]), size=1.2)

> text(2.6,6.5, bquote(rho[1]), size=1.2)

> text(2.25,6, bquote(rho[1]), size=1.2)

> text(2.9,6, bquote(rho[1]), size=1.2)

> text(2.6,7.3, bquote(rho[1]), size=1.2)

> text(2.1,9.3,"Job Secure", size=1.2, font=2)

> text(3.1,9.3,"Job Tenure", size=1.2, font=2)

> text(3,2.9,"Full Time", size=1.2, font=2)

> rect(1.5, 2.35, 4, 10)

> rect(3.7, 2.35, 4, 10, col= rgb(0.5,0.5,0.5,alpha=0.25), density=12)

> segments(3.7,2.35,3.7,10, col="black")

> text(3.85, 6.5, bquote(rho[3]))

> dev.off()
RStudioGD 
        2 

> ###############################################
> #Figure 3: Risk Type and Social Spending 
> #Author: Raluca L. Pahontu
> ###############################################
> 
> mydata <- read.dta13("shp.dta", convert.factors = FALSE)

> mydata$rho <- factor(mydata$rho, levels=c(1,2,3))

> fig3 <- ggplot(mydata, aes(rho, social_spending)) +
+   stat_summary(fun=mean, geom="bar", width=.5, fill="gray85", position= "dodge",  color="gray85") +
+   stat_summary(fun.data =mean_cl_normal, geom="errorbar", width=.07, size=.8, color="black",
+                position=position_dodge(width = .5))  +
+   theme(panel.background = element_blank(),
+         panel.grid.major = element_line(linetype = "dotted", size=.4, colour="grey90"),
+         panel.grid.minor = element_line(linetype = "dotted", size=.4, colour="grey90"),
+         axis.line.y = element_line(colour = "Black", linetype = "solid"),
+         axis.ticks.length=unit(0.3,"cm"),
+         axis.text = element_text(colour ="black", size=14),
+         axis.title = element_text(size=16),
+         axis.ticks.x = element_blank()) + 
+   ylab("Average Social Spending (%)\n") +   xlab("\n Type") + 
+   scale_x_discrete(breaks = c(3,2,1),  
+                    labels= c(expression(paste(rho, 1)),expression(paste(rho,2)), expression(paste(rho,3))), 
+                    limits=c("3", "2", "1")) +
+   scale_y_continuous(limits = c(.4,.8),  expand = c(0,0), oob=rescale_none) +
+   coord_cartesian(ylim=c(.4,.8)) 

> ggsave("figure3.pdf")

> ###################################################
> #Figure 4: Spending Demand By Income and Risk Type
> #Author: Raluca L. Pahontu
> ###################################################
> 
> mydata <- read.dta13("shp.dta", convert.factors = FALSE)

> mydata$rho <- factor(mydata$rho, levels=c(1,2,3))

> plotdata <- mydata[which(mydata$log_household_income>9&mydata$log_household_income<13),]

> fig4a <- ggplot(plotdata, aes(log_household_income)) +
+   geom_density(aes(fill=as.factor(rho)), alpha=.4) +
+   scale_fill_manual(values=c("black", "grey50", "grey90"), labels=c(expression(paste(rho,3)), expression(paste(rho,2)), expression(paste(rho,1))), name="Type")+
+   theme_bw() + 
+   theme(legend.key=element_blank(),
+         legend.text=element_text(color="black", size=10),
+         panel.background = element_blank(),
+         panel.border = element_blank(),
+         panel.grid.major = element_line(linetype = "dotted", size=.4, colour="grey90"),
+         panel.grid.minor = element_line(linetype = "dotted", size=.4, colour="grey90"),
+         axis.title.y = element_text(margin = margin(t = 0, r = 15, b = 0, l = 0)),
+         axis.title.x = element_text(margin = margin(t = 10, r = 20, b = 0, l = 0)),
+         axis.ticks.length=unit(0.3,"cm"),
+         axis.text = element_text(colour ="black")) + ylab("Density") + xlab("Log Income") + 
+   coord_cartesian(ylim=c(0, 1), xlim=c(9,13)) +
+   geom_segment(x=8.999, xend=13.001, y=-0.05, yend=-0.05, col="black")  +
+   geom_segment(x=8.8, xend=8.8, y=0, yend=1, col="black") 

> #and 
> 
> mydata2 <- read.dta13("margins_income.dta")

> mydata2$rho=factor(mydata2$rho, levels=c(1,2,3), labels = c(expression(paste(rho,1)), expression(paste(rho,2)), expression(paste(rho,3))))

> fig4b <-ggplot(data = mydata2, aes(x = as.numeric(income_distance), y = ss_hat, group = rho )) +
+   geom_errorbar(aes(ymin=ss_hat-1.96*se, ymax=ss_hat+1.96*se, colour=rho), width=.05, size=.4) + 
+   geom_line(aes(colour=rho),linetype="dotted",  size=0.2) + 
+   geom_point(aes(colour=rho), size=1.5,  stroke=1.2) + 
+   scale_colour_manual(values=c("black","grey40","grey70"),labels=c(expression(paste(rho,3)), expression(paste(rho,2)), expression(paste(rho,1))), name="Type") + 
+   xlab("Income Distance from Mean") + 
+   ylab("Predicted Social Spending") + 
+   theme_bw() + 
+   theme(legend.key=element_blank(),
+         legend.text=element_text(color="black", size=10),
+         panel.background = element_blank(),
+         panel.border = element_blank(),
+         panel.grid.major = element_line(linetype = "dotted", size=.4, colour="grey90"),
+         panel.grid.minor = element_line(linetype = "dotted", size=.4, colour="grey90"),
+         axis.title.y = element_text(margin = margin(t = 0, r = 15, b = 0, l = 0)),
+         axis.title.x = element_text(margin = margin(t = 10, r = 20, b = 0, l = 0)),
+         axis.ticks.length=unit(0.3,"cm"),
+         axis.text = element_text(colour ="black"))   + 
+   coord_cartesian(ylim=c(0.2, .8), xlim=c(-1.5,1.5))  + 
+   scale_x_continuous(breaks=c(-1.5, -1, -.5, 0, 0.5, 1, 1.5)) + 
+   geom_segment(x=-1.5, xend=1.5, y=.17, yend=.17, col="black") +
+   geom_segment(x=-1.65, xend=-1.65, y=0.2, yend=.8, col="black") 

> library(ggpubr)

> ggarrange(fig4a, fig4b, legend = "bottom")

> ggsave("figure4.pdf")

> ####################################################################################
> #Figure D2: Distribution of $\rho_1$ and $\rho_2$ in Skill Specific, Offshore, RTI
> #Author: Raluca L. Pahontu
> ####################################################################################
> 
> data <- read.dta13("shp_ss_off.dta")

> #skillspecific
> tab.ss <- table(data$skill_specificity, data$rho)

> df.ss <- as.data.frame(prop.table(tab.ss, 2) )

> df.ss <- df.ss[27:78,]

> ss <- ggplot(df.ss, aes(fill=Var2, y=Freq, x=Var1)) + 
+   geom_bar( stat="identity", width=0.99, colour="grey60") +
+   scale_fill_manual(values=alpha(c("black", "grey60"), 0.2), name="Work Type", labels=c("rho2", "rho1")) + theme_bw() +
+   theme(axis.text.x = element_blank(), axis.ticks.x = element_blank()) + xlab("Skill Specificity (Ascending Order)") + ylab("Frequencies") 

> #offshore
> tab.off <- table(data$offshore1, data$rho)

> df.off <- as.data.frame(prop.table(tab.off, 2) )

> df.off <- df.off[22:63,]

> off <- ggplot(df.off, aes(fill=Var2, y=Freq, x=Var1)) + 
+   geom_bar( stat="identity",  width=0.99, colour="grey60") +
+   scale_fill_manual(values=alpha(c("black", "grey60"), 0.2), name="Work Type", labels=c("rho2", "rho1")) + theme_bw() +
+   theme(axis.text.x = element_blank(), axis.ticks.x = element_blank()) + xlab("Offshoring (Ascending Order)") + 
+   ylab(" ")

> #rti
> 
> tab.rti <- table(data$rti, data$rho)

> df.rti <- as.data.frame(prop.table(tab.rti, 2) )

> df.rti <- df.rti[22:63,]

> rti <- ggplot(df.rti, aes(fill=Var2, y=Freq, x=Var1)) + 
+   geom_bar( stat="identity",  width=0.99, colour="grey60") +
+   scale_fill_manual(values=alpha(c("black", "grey60"), 0.2), name="Work Type", labels=c("rho2", "rho1")) + theme_bw() +
+   theme(axis.text.x = element_blank(), axis.ticks.x = element_blank()) + xlab("RTI (Ascending Order)") + 
+   ylab(" ")

> ggarrange(ss,off,rti, common.legend = T, ncol=3, legend = "bottom")

> ggsave(file="fig_d2.pdf")

> ##############################
> #Figure D3: Risk and Idelogy
> #Author: Raluca L. Pahontu
> ##############################
> 
> mydata <- read.dta13("shp.dta", convert.factors = FALSE)

> mydata$rho=factor(mydata$rho, levels=c(1,2,3))

> risk_ideo <- ggplot(mydata, aes(reorder(as.factor(left), -spending_demand), spending_demand, fill=rho))  

> risk_ideo +  
+   stat_summary(fun.y=mean, 
+                geom="bar",
+                width=.3,
+                position="dodge") +
+   stat_summary(fun.data =mean_cl_normal, 
+                geom="errorbar",
+                width=.1, 
+                position=position_dodge(width=.3))  +
+   scale_x_discrete(labels= c("Left-Wing", "Right_Wing")) +
+   ylab("Average Social Spending (%)") + 
+   xlab("Ideology") + 
+   scale_fill_manual(labels=c("3", "2", "1"), values=c("grey80", "grey60", "grey40"), name= "Risk Level") + theme_bw() + 
+   coord_cartesian(ylim=c(0,.8)) 

> ggsave(file="figure_d3.eps")

> ######################################################
> #Figure D4: Unemployment Spending and Social Spending
> #Author: Raluca L. Pahontu
> #####################################################
> 
> mydata3 <- read.dta13("dataunemplsocial.dta")

> counts <- table(mydata3$unempl_spending, mydata3$social_spending)

> percentages <- prop.table(counts,1) 

> df <- as.data.frame(percentages) 

> lim <- c(0, max(df$Freq) + 0.2)

> ggplot(df, aes(x=Var2, y=Freq, group=Var1)) + 
+   geom_bar(aes(fill = Var1), stat="identity", position = "dodge", width = .5)  + 
+   ylab("Percent") + xlab("Social Spending") + 
+   scale_fill_manual(labels=c("Less", "Same", "More"), values=c("grey80", "grey60", "grey40"), name= "Unemployment Spend")+ 
+   scale_x_discrete(labels=c("Less", "Same", "More")) +
+   scale_y_continuous(limits=lim, expand= c(0,0)) + theme_bw() 

> ggsave(file="figure_d4.eps")

> ######################################################
> #Figure D5: Public Swiss Social Spending (%GDP)
> #Author: Raluca L. Pahontu
> #####################################################
> 
> data_spending <- read.dta13("swiss_spending_oecd_data.dta") 

> spend <- ggplot(data=subset(data_spending, year<=1999), aes(x=year, y=spending)) 

> spend +   
+   geom_line(linetype="dashed") + 
+   ylab ("Social Spending (% GDP)") + 
+   xlab("Year") + 
+   geom_line(data=subset(data_spending, year>=1999 ), aes(x=year, y=spending)) + 
+   geom_vline(xintercept=c(1999), linetype="solid", color="black") + 
+   coord_cartesian(ylim=c(0,25)) +
+   scale_y_continuous(limits = c(0,25),  expand = c(0,0), oob=rescale_none) + 
+   scale_x_continuous(breaks = c(1980, 1985, 1990, 1995, 1999, 2005, 2010, 2015))  + theme_bw()

> ggsave(file="figure_d5.eps")

> ######################################################
> #Figure D6: Robustness Within Risk Type
> #Author: Raluca L. Pahontu
> #####################################################
> 
> data_rho2 <- read.dta13("robustwithin_rho2.dta")

> library(tidyverse)

> newdf_rho2 <- data_rho2 %>% 
+   gather(variable, value, -var)%>%
+   spread(var, value)

> newdf_rho2$id <- c(1,2,3)

> newdf_rho2$id <- as.factor(newdf_rho2$id)

> g_rho2<- ggplot() + 
+   geom_pointrange(data=newdf_rho2, mapping=aes(x=id, y=coef, ymin=ci_upper, 
+                                                ymax=ci_lower), color="black", size=1.2, fatten=2, fill="black", shape=21) +
+   scale_x_discrete(limit=c("1", "2", "3"), labels= c("!FT,!JT,JS", "!FT,JT,!JS", "!FT,!JT,!JS")) + 
+   xlab("Indicator")  + ylab("Estimate on Social Spending Demand") +
+   geom_hline(yintercept=0, col="black", lwd=0.4, lty="solid")  +  
+   theme_bw() + 
+   theme(legend.key=element_blank(),
+         legend.text=element_text(color="black", size=10),
+         panel.grid.major = element_line(linetype = "dotted", size=.4, colour="grey90"),
+         panel.grid.minor = element_line(linetype = "dotted", size=.4, colour="grey90"),
+         axis.title.y = element_text(margin = margin(t = 0, r = 15, b = 0, l = 0)),
+         axis.title.x = element_text(margin = margin(t = 10, r = 20, b = 0, l = 0)),
+         axis.ticks.length=unit(0.3,"cm"),
+         axis.text = element_text(colour ="black"))  + 
+   coord_flip()  + 
+   ylim(-.15,.15)

> g_rho2

> data_rho1 <- read.dta13("robustwithin_rho1.dta")

> newdf_rho1 <- data_rho1 %>% 
+   gather(variable, value, -var)%>%
+   spread(var, value)

> newdf_rho1$id <- c(1,2,3)

> newdf_rho1$id <- as.factor(newdf_rho1$id)

> g_rho1<- ggplot() + 
+   geom_pointrange(data=newdf_rho1, mapping=aes(x=id, y=coef, ymin=ci_upper, 
+                                                ymax=ci_lower), color="black", size=1.2, fatten=2, fill="black", shape=21) +
+   scale_x_discrete(limit=c("1", "2", "3"), labels= c("JS,FT,!JT", "FT,JT,!JS", "FT,JS,JT,")) + 
+   xlab("Indicator")  + ylab("Estimate on Social Spending Demand") +
+   geom_hline(yintercept=0, col="black", lwd=0.4, lty="solid")  +  
+   theme_bw() + 
+   theme(legend.key=element_blank(),
+         legend.text=element_text(color="black", size=10),
+         panel.grid.major = element_line(linetype = "dotted", size=.4, colour="grey90"),
+         panel.grid.minor = element_line(linetype = "dotted", size=.4, colour="grey90"),
+         axis.title.y = element_text(margin = margin(t = 0, r = 15, b = 0, l = 0)),
+         axis.title.x = element_text(margin = margin(t = 10, r = 20, b = 0, l = 0)),
+         axis.ticks.length=unit(0.3,"cm"),
+         axis.text = element_text(colour ="black"))  + 
+   coord_flip()  + 
+   ylim(-.08,.08)

> g_rho1

> library(ggpubr)

> ggarrange(g_rho2, g_rho1, ncol=2)

> ggsave(file="figure_d6.eps")

> ######################################################
> #Figure D7: Spending Demand by Risk Type Over Time
> #Author: Raluca L. Pahontu
> #####################################################
> 
> data <- read.dta13("rdata_trends.dta")

> ggplot(data, aes(as.factor(year), spending_mean, group=as.factor(rho), color=as.factor(rho))) +
+   geom_point(size = 2) +
+   geom_line(stat = "smooth", method = "lm", span = 1,  size = 2, alpha = 0.4) + 
+   xlab("Year") + ylab("Mean Social Spending") +
+   scale_color_manual(values=c("black","grey40","grey70"), name="Work Type", 
+                      labels=c(expression(paste(rho,3)), expression(paste(rho,2)), expression(paste(rho,1)))) + 
+   theme_bw() +
+   theme(legend.key=element_blank(),
+         legend.text=element_text(color="black", size=10),
+         panel.background = element_blank(),
+         panel.border = element_blank(),
+         panel.grid.major = element_line(linetype = "dotted", size=.4, colour="grey90"),
+         panel.grid.minor = element_line(linetype = "dotted", size=.4, colour="grey90"),
+         axis.title.y = element_text(margin = margin(t = 0, r = 15, b = 0, l = 0)),
+         axis.title.x = element_text(margin = margin(t = 10, r = 20, b = 0, l = 0)),
+         axis.ticks.length=unit(0.3,"cm"),
+         axis.text = element_text(colour ="black"))  +
+   coord_cartesian(ylim=c(.2, .8)) +
+   geom_segment(x=0.4, xend=0.4, y=0.2, yend=0.8, col="black") +
+   geom_segment(x=1, xend=13, y=0.17, yend=.17, col="black") 

> ggsave("figure_d7.pdf")

> ##############################################################
> #Figure D8: Variation in Risk $\rho_2$ Within ISCO1 Over Time
> #Author: Raluca L. Pahontu
> ##############################################################
> 
> rho.occup <- read.dta13("risk_occup_distribution.dta")

> ggplot(rho.occup,aes(x=year,y=toplot, color=toplot)) + 
+   geom_point(size = 2) + scale_colour_gradient(low="green", high="red", name=expression(paste(Delta,rho, 2))) + facet_wrap(~occup1) + 
+   geom_line(stat = "smooth", method = "loess",  span = .5, size = 2, alpha = 0.4) + 
+   theme_bw() + ylab(" ") + xlab("Year") + ylim(-.3,0.3)  

> ggsave("figure_d8.pdf")

> ##############################################
> #Figure D9: Spending Demand by OUR Over Time
> #Author: Raluca L. Pahontu
> ##############################################
> 
> data.our <- read.dta13("shp_and_rehm_our.dta")

> our1 <- ggplot(data.our,aes(x=year,y=spending_mean,colour=our, line=as.factor(isco1))) + 
+   geom_point(size = 2) + scale_colour_gradient(low="black", high="red", name="OUR") + facet_wrap(~isco1) + 
+   geom_line(stat = "smooth", method = "loess",  span = 1, size = 2, alpha = 0.4) + 
+   theme_bw() + ylab("Mean Spending Demand") + xlab("Year") + ylim(0.3,0.8)

> our2 <- ggplot(data.our,aes(x=year,y=spending_mean,colour=our, line=as.factor(isco1))) + 
+   geom_line() + 
+   geom_point(size = 2) + scale_colour_gradient(low="black", high="red", name="OUR") + 
+   theme_bw() + ylab("Mean Spending Demand") + xlab("Year") +ylim(0.3,0.8)

> ggarrange(our1, our2, ncol=2, common.legend = T)

> ggsave(file="figure_d9.pdf")
